package com.jxt.myjxtmanager.ui.model;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.jxt.myjxtmanager.entity.FeedbackBean;
import com.jxt.myjxtmanager.okHttp.Result;
import com.jxt.myjxtmanager.okHttp.ResultCallback;
import com.jxt.myjxtmanager.ui.inter.OnGenericResultListener;
import com.jxt.myjxtmanager.views.CustomProgressDialog;
import com.squareup.okhttp.Request;

/**
 * Created by Administrator on 2017/2/16 0016.
 */
public class FeedbackModel {
    private Context context;
    private OnGenericResultListener onGenericResultListener;

    public FeedbackModel(Context context) {
        this.context = context;
    }

    public void httpFeekback(Context context, long user_id, FeedbackBean feedbackBean, OnGenericResultListener onGenericResultListener) {
        this.onGenericResultListener = onGenericResultListener;
//        HttpClient.getInstance().httpsFeedback(context,user_id,feedbackBean,new callBackFeedbacl());
        loadData();
    }

    private void loadData() {
        //模拟网络加载
        Message message = new Message();
        message.arg1 = 2;
        loadDataHandler.sendMessageDelayed(message, 1000);
    }

    private Handler loadDataHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            onGenericResultListener.onSuccess(new Result());
        }
    };

    class callBackFeedbacl extends ResultCallback<Result> {
        CustomProgressDialog dialog;

        @Override
        public void onResponse(int code, String msg) {
            super.onResponse(code, msg);
            onGenericResultListener.onFailure(code, msg);
        }

        @Override
        public void onResponse(Result response) {
            super.onResponse(response);
            onGenericResultListener.onSuccess(response);
        }

        @Override
        public void onError(int code, String message) {
            super.onError(code, message);
            onGenericResultListener.onFailure(code, message);
        }

        @Override
        public void onFailure(Request request, Exception e) {
            super.onFailure(request, e);
            onGenericResultListener.onFailure(4, "网络延迟了");
        }

        @Override
        public void onFinish() {
            super.onFinish();
            if (dialog != null) {
                dialog.dismiss();
                dialog = null;
            }
        }

        @Override
        public void onStart() {
            super.onStart();
            dialog = new CustomProgressDialog(context, "");
            dialog.showDialog();
        }
    }
}
